<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>layout 后台大布局 - Layui</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">

<link rel="stylesheet" href="css/layui.css" media="all">
</head>
<body class="layui-layout-body">

	<div class="layui-layout layui-layout-admin">
		<div class="layui-header">
			<div class="layui-logo">爱阅电子书城</div>
			<!-- 头部区域（可配合layui已有的水平导航） -->
			<ul class="layui-nav layui-layout-right">
				<li class="layui-nav-item"><a href="javascript:;"> <img
						src="http://t.cn/RCzsdCq" class="layui-nav-img"> <%=session.getAttribute("adminName")%>
				</a>
					<dl class="layui-nav-child">
						<dd>
							<a href="javascript:adminInfofun('${user.userName}')">基本资料</a>
						</dd>
						<dd>
							<a href="">安全设置</a>
						</dd>
					</dl></li>
				<li class="layui-nav-item"><a href="">退了</a></li>
			</ul>
		</div>

		<div class="layui-side layui-bg-black">
			<div class="layui-side-scroll">
				<!-- 左侧导航区域（可配合layui已有的垂直导航） -->
				<ul class="layui-nav layui-layout-right" lay-filter="test">
					<li class="layui-nav-item "><a class="">图书管理</a>
						<dl class="layui-nav-child">
							<dd>
								<a href="addBookInfo.jsp">添加图书</a>
							</dd>
							<dd>
								<a href="bookInfo.jsp">图书信息</a>
							</dd>

						</dl></li>

					<li class="layui-nav-item"><a class="">图书类型管理</a>
						<dl class="layui-nav-child">
							<dd>
								<a href="addBookTypeInfo.jsp">添加图书类型</a>
							</dd>
							<dd>
								<a href="bookTypeInfo.jsp">图书类型信息</a>
							</dd>

						</dl></li>

					<li class="layui-nav-item"><a class="">用户管理</a>
						<dl class="layui-nav-child">
							<dd>
								<a href="addUsers.jsp">添加用户</a>
							</dd>
							<dd>
								<a href="userInfo.jsp">用户信息</a>
							</dd>

						</dl></li>
					<li class="layui-nav-item"><a class="">订单管理</a>
						<dl class="layui-nav-child">
							<dd>
								<a href="adminOrders.jsp">订单查询</a>
							</dd>

						</dl></li>
				</ul>
			</div>
		</div>


		<div class="layui-body">
			<!-- 内容主体区域 -->
			<div style="padding: 15px;">
				<fieldset class="layui-elem-field layui-field-title"
					style="margin-top: 30px;">
					<legend>查看图书信息</legend>
				</fieldset>
				<div style="float: right; padding-bottom: 25px">
					<form class="navbar-form navbar-right" action="BookServlet"
						method="post">
						<div style="float: left;">
							<input type="text" class="layui-input" name="keyname"
								id="keyname" value="${key}" placeholder="关键字"
								style="width: 150px;">

						</div>
						<div style="float: left;">
							<button class="layui-btn layui-btn-normal" type="submit">查询</button>
						</div>

					</form>
				</div>
				<table class="layui-table">
					<thead>
						<tr>
							<th>ID</th>
							<th>图书</th>
							<th>图书名称</th>
							<th>作者</th>
							<th>图书简介</th>
							<th>出版社</th>
							<th>价格</th>
							<th>数量</th>
							<th>种类</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>


						<c:if test="${pd==null}">
							<c:redirect url="BookServlet"></c:redirect>
						</c:if>
						<c:if test="${pd!=null}">
							<c:forEach items="${pd.data}" var="book">
								<tr>
									<td>${book.bookId}</td>
									<td><img src="/images/${book.bookUrl}" alt=" "
										class="img-responsive" style="width: 80px; height: 100px"></td>
									<td>${book.bookName}</td>
									<td>${book.author}</td>
									<td style="width: 350px;">${book.bookDescribe}</td>
									<td>${book.press}</td>
									<td>${book.price}</td>
									<td>${book.count}</td>
									<td>${book.typeName}</td>
									<td><a class="layui-btn layui-btn-xs updatebook" lay-event="edit"
									href="javascript:bookfun('${book.bookId}')">编辑</a> <a
										class="layui-btn layui-btn-danger layui-btn-xs delbook"
										lay-event="del">删除</a></td>

								</tr>
							</c:forEach>
						</c:if>
					</tbody>
				</table>
				<div id="demo7" style="text-align: center;"></div>
				<script type="text/html" id="barDemo"></script>

				<script src="layui/layui.all.js" charset="utf-8"></script>
				<script src="js/jquery-2.0.3.js"></script>
				<script src="layui/layui.js" charset="utf-8"></script>
				<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
				<script>
				layui.use(['laypage', 'layer'], function(){
                    var laypage = layui.laypage
                    ,layer = layui.layer;
                    
                    laypage.render({
                 	    elem: 'demo7'
                 	    ,count: ${pd.totalCount}
                         ,curr: ${pd.page}
                         ,limit: ${pd.pageSize}
                         ,limits:[10,20,30,40,50]
                 	    ,layout: ['count', 'prev', 'page', 'next', 'limit','refresh', 'skip']
                 	    ,jump: function(obj, first){
                 	        //obj包含了当前分页的所有参数，比如：
                 	        //console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                 	        //console.log(obj.limit); //得到每页显示的条数
                 	        
                 	        //首次不执行
                 	        if(!first){
                 	          //do something
                 	        	  location.href="BookServlet?page="+obj.curr+"&pageSize="+obj.limit+"&keyname="+$("#keyname").val();
                 	        }
                 	      }
                 	    });
                    
                    $(".delbook").click(function(){
                  	  //$(this).parents("tr") 当前行
                  	  //find("td") 这个tr下的所有td
                  	  //eq(0) 所有td中的第一个
                  	  //text() ->innerText td中的文本内容
                  	  var bookId = $(this).parents("tr").find("td").eq(0).text();
                  	  //1 提示用户是否删除.使用layui的layer组件弹窗提示
                  		//询问框
                  	  layer.confirm('是否确定删除编号为'+bookId+"的类型", {
                  	    btn: ['确定','取消'] //按钮
                  	  }, function(){
                  	    //layer.msg('确定的时候要执行的代码', {icon: 1});
                  	    //ajax请求
                  	    $.ajax({
                  	    	//参数
                  	    	url: "BookServlet",
                  	    	type: "post",
                  	    	data:{
                  	    		bookId: bookId,
                  	    		op: "del"
                  	    	},
                  	    	success: function(res){
                  	    		//判断返回值的结果，根据结果做提示以及后续的页面刷新操作
                  	    		if(res.msg == "true")
                  	    			{
                  	    			
                  	    			layer.msg('删除成功!', {
                  	    				icon: 1,
                  	    			    time: 2000, //2s后自动关闭
                  	    			    btn: ['确定']
                  	    			  },function(){
                  	    				  
                  	    				  //页面刷新
                  	    				  location.href="BookServlet?&page="+${pd.page}+"&pageSize="+${pd.pageSize}+"&keyname="+$("#keyname").val();	    				  
                  	    			  });	    					    			
                  	    			}
                  	    		else{
                  	    			
                  	    			layer.msg('删除失败!', {
                  	    				icon: 1,
                  	    			    time: 2000, //2s后自动关闭
                  	    			    btn: ['确定']
                  	    			  });
                  	    			
                  	    		}
                  	    		
                  	    	},
                  	    	dataType: "json"
                  	    });
                  	  });		    
                    });
                   /* $(".updatebook").click(function(){
                    	  
                    	  //得到类型的typeid
                    	  var typeid=$(this).parents("tr").find("td").eq(0).text();
                    	  var typename=$(this).parents("tr").find("td").eq(1).text();
                    	  var typeremark=$(this).parents("tr").find("td").eq(2).text();
                    	  
                    	  $("#typeid").val(typeid);
                    	  $("#typename").val(typename);
                    	  $("#typeremark").val(typeremark);
                    	  
                    	
                    	//弹出层
                    	  layer.open({
                    		  type: 1,
                    		  area: ['600px', '400px'],
                    		  content: $('#updatediv') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
                    		}); */
                  
                 });
				</script>

				
			</div>
		</div>

		<div class="layui-footer">
			<!-- 底部固定区域 -->
			© layui.com - 底部固定区域
		</div>
	</div>
	<script>
	<!--跳转到图书信息修改-->
	function bookfun(bookId){
		location.href = "http://localhost:8080/love_reading_ebook_city/BookServlet?op=queryById&bookId="
			+ bookId;
	} 

               <!--跳转到个人信息-->
		function adminInfofun(adminName){
			location.href = "http://localhost:8080/love_reading_ebook_city/AdminServlet?op=admininfo&adminName="
				+ adminName;
		} 
		</script>
</body>
</html>
